class Solution {
public:
    vector<int> missingTwo(vector<int>& nums) {
        int ans = 0;
        int n = nums.size();
        for (auto x : nums)ans ^= x;
        for (int i = 1; i <= n + 2; i++)ans ^= i;
        int idx = 0;
        int ans1 = 0, ans2 = 0;
        for (int i = 0; i < 31; i++) {
            if (ans & (1 << i)) {
                idx = i;
                break;
            }
        }
        for (auto x : nums) {
            if (x & (1 << idx))ans1 ^= x;
            else ans2 ^= x;
        }
        for (int i = 1; i <= n + 2; i++) {
            if (i & (1 << idx))ans1 ^= i;
            else ans2 ^= i;
        }
        vector<int>ans3;
        ans3.push_back(ans1);
        ans3.push_back(ans2);
        return ans3;
    }
};